package com.springbootblog.service.serviceImpl.fontend;

import com.springbootblog.controller.fontend.IndexController;
import com.springbootblog.dao.ToolsDao;
import com.springbootblog.pojo.Tools;
import com.springbootblog.pojo.ToolsCategory;
import com.springbootblog.service.fontend.ToolsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ToolsServiceImpl implements ToolsService
{
    /**
     * 定义一个静态常量日志对象
     */
    private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

    /**
     * 自动装载（dao接口注入）
     */
    @Autowired
    private ToolsDao toolsDao;

    @Override
    public Map<String, Object> getToolsList(String category_id)
    {
        // System.out.println(category_id);
        // 先查分类
        List<ToolsCategory > toolsCategoryList = toolsDao.getToolsCategoryList();
        if(category_id.isEmpty() ||  category_id == null || category_id.equals("0"))
        {
            category_id = "1";
        }
        // 查分类下的所有网站
        List<Tools> toolsList = toolsDao.getToolsListByCategoryId(category_id);
        Map<String,Object> result = new HashMap<>(3);
        result.put("array",toolsCategoryList);
        result.put("toolsList",toolsList);
        return result;
    }
}
